#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "header/loadFile.h"
#include "header/parseArgs.h"
#include "header/checkFile.h"
#include "header/errors.h"
#include "header/headers.h"

#define TEMP_FILE "temp.c"

void printHelp(void);

int main(const int argc, const char **argv) {
    int filesLoaded = 0, i, j = 0, flag = 0;
    int size = -1, include = 0, random = 2;
    char *content[argc-1], *files[argc-1];
    FILE *fp;

    if((fp = fopen(TEMP_FILE, "w")) == NULL) {
        printError(2); /* File open failed */
        return 1;
    }
    
    size = parseArguments((argc-1), &argv[1], files);
    if(size == 0) {
        fprintf(stderr, "No files opened!\n");
        return 1;
    }

    for(i = 0; i < size; i++) {
        loadToMem(files[i], &content[i]);
        checkFile(content[i]);
        ++filesLoaded;
    }
    
    for(i = 0; i < filesLoaded; i++) {
        free(content[i]);
    }

    fclose(fp);
    if(remove(TEMP_FILE)) {
        printError(2); /* File handling failed */
    }
    return 0;
}

void printHelp(void) {
    printf("INclude CHecker for ANSI-C\n");
    printf("Pass filenames as arguments.\n");    
}
